﻿using System.Configuration;

namespace BSDS.Commands.Configuration
{
    [ConfigurationCollection(typeof(MailingConfigurationRecipientElement), CollectionType = ConfigurationElementCollectionType.AddRemoveClearMap)]
    public class MailingConfigurationReciptientsCollection : ConfigurationElementCollection
    {
        public MailingConfigurationRecipientElement this[int index]
        {
            get { return (MailingConfigurationRecipientElement) BaseGet(index); }
            set
            {
                if (BaseGet(index) != null)
                {
                    BaseRemoveAt(index);
                }
                base.BaseAdd(index, value);
            }
        }

        public new MailingConfigurationRecipientElement this[string name]
        {
            get { return (MailingConfigurationRecipientElement) BaseGet(name); }
        }

        #region Overrides

        protected override ConfigurationElement CreateNewElement()
        {
            return new MailingConfigurationRecipientElement();
        }

        protected override object GetElementKey(ConfigurationElement element)
        {
            return ((MailingConfigurationRecipientElement)element).Email;
        }

        #endregion
    }
}